home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.0 KB | 171 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWCouPtr.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWCOUPTR_H
- #define FWCOUPTR_H
-
- #ifndef FWAUTODE_H
- #include "FWAutoDe.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // Forward class declaration
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CCountedPtrRep;
-
- //========================================================================================
- // CLASS FW_CCountedPtr
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CCountedPtr FW_AUTO_DESTRUCT_OBJECT
- {
- public:
- FW_CCountedPtr();
- // Creates a "NULL" pointer.
-
- virtual ~ FW_CCountedPtr();
- // Destroy the pointer.
- // Decrements the count in the rep, and deletes the rep if count is zero.
-
- FW_CCountedPtr(const FW_CCountedPtr& other);
- // FW_SPlatformPoint this pointer to the same rep as the other pointer points to.
-
- FW_CCountedPtr(FW_CCountedPtrRep* rep);
- // Creates a pointer pointing at rep.
-
- FW_CCountedPtr& operator=(const FW_CCountedPtr& other);
- // Assignment, point this ponter to the same rep as the other pointer points to.
-
- FW_CCountedPtr& operator=(FW_CCountedPtrRep* rep);
- // Assignment, point this ponter to rep.
-
- FW_CCountedPtrRep* operator->() const; // Must be overlodded by subclass
- // Provide access to members of rep.
-
- FW_CCountedPtrRep& operator*() const;
- // Provide access to rep.
- // This operator should be used only if operator->() is not sufficient.
-
- FW_Boolean operator==(const FW_CCountedPtr& other) const;
- // Points to the same representation object?
-
- FW_Boolean operator!=(const FW_CCountedPtr& other) const;
- // Points to a different representation object?
-
- operator const void*() const;
- // Use to test if this is a "NULL" pointer.
-
- protected:
- void SetRep(FW_CCountedPtrRep* rep);
-
- private:
-
- void UpCount();
- // Implementation method, increment the reference count in rep.
-
- void DownCount();
- // Implementation method, decrement the reference count in rep.
- // Deletes rep if reference count is zero.
-
- protected:
- FW_CCountedPtrRep *fRep;
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::operator->
- //----------------------------------------------------------------------------------------
-
- inline FW_CCountedPtrRep* FW_CCountedPtr::operator->() const
- {
- return fRep;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::operator*
- //----------------------------------------------------------------------------------------
-
- inline FW_CCountedPtrRep& FW_CCountedPtr::operator*() const
- {
- return *fRep;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::operator==
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CCountedPtr::operator==(const FW_CCountedPtr& other) const
- {
- return (fRep == other.fRep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::operator!=
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CCountedPtr::operator!=(const FW_CCountedPtr& other) const
- {
- return !operator==(other);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtr::operator const void*
- //----------------------------------------------------------------------------------------
-
- inline FW_CCountedPtr::operator const void*() const
- {
- return (const void*) fRep;
- }
-
- //========================================================================================
- // CLASS FW_CCountedPtrRep
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CCountedPtrRep
- {
- public:
-
- FW_CCountedPtrRep();
- virtual ~ FW_CCountedPtrRep();
-
- long IncrementReferenceCount();
- long DecrementReferenceCount();
-
- private:
- unsigned long fRefCount;
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtrRep::DecrementReferenceCount
- //----------------------------------------------------------------------------------------
-
- inline long FW_CCountedPtrRep::DecrementReferenceCount()
- {
- return --fRefCount;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCountedPtrRep::IncrementReferenceCount
- //----------------------------------------------------------------------------------------
-
- inline long FW_CCountedPtrRep::IncrementReferenceCount()
- {
- return ++fRefCount;
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-